//
//  Point.swift
//  WBDemo
//
//  Created by Jin on 26/04/2018.
//  Copyright © 2018 com.baidu.123. All rights reserved.
//

import Foundation

//基类
class Point2D: Codable {
    var x = 0.0
    var y = 0.0
    
    private enum CodingKeys:String,CodingKey{
        case x
        case y
    }
    
    func encode(to encoder:Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(x, forKey: .x)
        try container.encode(y, forKey: .y)
    }
}

//派生类
class Point3D: Point2D {
    var z = 0.0
    
    private enum CodingKeys:String,CodingKey{
        case z
        case point_2d
    }
    
    override func encode(to encoder:Encoder) throws {
        
        var container = encoder.container(keyedBy: CodingKeys.self)
        try super.encode(to: container.superEncoder(forKey:.point_2d))
        try container.encode(z, forKey: .z)
    }
}
